public class TestLinkedlist {
    //14.将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的
    //设计一个傀儡节点
    public ListNode mergeTwoLists(ListNode headA, ListNode headB) {
        if(headA==null){
            return headB;
        }
        if(headB==null){
            return headA;
        }
        if(headA==null || headB==null){
            return null;
        }
        ListNode newHead = new ListNode();
        ListNode tmp = newHead;
        while(headA != null && headB != null){
            if(headA.val < headB.val){
                tmp.next=headA;
                tmp=headA;
                headA=headA.next;
            }else{
                tmp.next=headB;
                tmp=headB;
                headB=headB.next;
            }
        }

        if(headA!=null){
            tmp.next = headA;
        }
        if(headB!=null){
            tmp.next = headB;
        }
        return newHead.next;
    }

    public static void main(String[] args) {
        Linkedlist linkedlist = new Linkedlist();
        //linkedlist.createList();
        linkedlist.addFirst(1);
        linkedlist.addFirst(2);
        linkedlist.addFirst(3);
        linkedlist.display();
        System.out.println(linkedlist.size());
        System.out.println("==========");
        linkedlist.addLast(4);
        linkedlist.addLast(5);
        linkedlist.addLast(6);
        linkedlist.display();
        System.out.println();
        System.out.println("=========");
        linkedlist.addIndex(2,9);
        linkedlist.display();
        System.out.println(linkedlist.contains(90));
        System.out.println();
        //System.out.println("要删除所有节点");
        //linkedlist.clear();
        //linkedlist.display();
        linkedlist.remove(1);
        linkedlist.remove(9);
        linkedlist.display();
        System.out.println();
        //打印反转链表
        linkedlist.reverseList();
        linkedlist.display();

    }
}
